
group = maya
project = maya-service
version = 0.1.3
server = 139.199.172.167:5000
# env=dev env=test env=prod
env = prod
prod =  prod
TIMESTAMP=$(shell date +%Y%m%d%H%M)

config:
	etcdctl put "/hello/config/maya-service"  < ./script/config.json

default:
	@echo ${group}/${project}

build:
	@echo "######### Executing Step build"
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64  go build -o ./bin/${project}
	cp -rf ./script/ ./bin/

image:build
	@echo "######### Executing Step image"
	docker login -u maya -p Maya123456 ${server}
	docker build -t ${group}/${project}:${env} --platform linux/amd64 --build-arg ARG_ENV_NAME=${env} --build-arg ARG_PROJECT_NAME=${project} .

push:image
	@echo "######### Executing Step push"
	docker tag ${group}/${project}:${env} ${server}/${group}/${project}:${env}-${version}
	docker push ${server}/${group}/${project}:${env}-${version}




deploy:
	@echo "######### Executing Step deploy"
ifeq (${env}, ${prod})
	# prod
	sshpass -p 83e5T8fLeD ssh quanxi@prod.shengu.info sudo docker pull ${server}/${group}/${project}:${env}-${version}
	sshpass -p 83e5T8fLeD ssh quanxi@prod.shengu.info sudo docker rm -f ${project}
	sshpass -p 83e5T8fLeD ssh quanxi@prod.shengu.info sudo docker run --name ${project} -d -u=root -p 8000:8000 --restart always -v /var/project/maya/logs:/app/bin/logs ${server}/${group}/${project}:${env}-${version}
	sshpass -p 83e5T8fLeD ssh quanxi@prod.shengu.info sudo docker image prune -a
else
	# test
	docker rm -f ${project}
	docker pull ${server}/${group}/${project}:${env}-${version}
	docker run --name ${project} -d -u=root -p 8000:8000 --restart always -v /var/project/maya/logs:/app/bin/logs ${server}/${group}/${project}:${env}-${version}
	#docker image prune -a
endif

.PHONY: defaul build image push deploy
all : default build image push